import { createRouter, createWebHashHistory } from 'vue-router'
// 导入公共布局容器
import Layout from '@/views/Layout'
// 首页
import Home from '@/views/Home'
// 一级目录页
import Category from '@/views/Category'

import SubCategory from '@/views/Category/sub.vue'

// 商品详情页
import Goods from '@/views/Goods'

// 登录页
const Login = () => import('@/views/Login')

// 测试
const Test = () => import('@/views/test')

// 第三方登录回跳页
const LoginCallBack = () => import('@/views/Login/callback')

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: Home
      },
      {
        path: '/category/:id',
        component: Category
      },
      {
        path: '/category/sub/:id',
        component: SubCategory
      },
      {
        path: '/goods/:id',
        component: Goods
      }
    ]
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/login/callback',
    component: LoginCallBack
  },
  {
    path: '/test',
    component: Test
  }
]

// vue2是new一个router实例
const router = createRouter({
  history: createWebHashHistory(), // hash模式 | createWebHistory history模式
  routes
})

export default router
